//
//  SFBarButtonItem + Extension.swift
//  SFWeiBo
//
//  Created by 孙凡 on 16/4/8.
//  Copyright © 2016年 Edward. All rights reserved.
//

import UIKit


extension UIBarButtonItem {

    
    convenience init(imageName:String?, title:String?, target:AnyObject?, SEL:Selector) {

        self.init()

        let button = UIButton()

        button.addTarget(target, action: SEL, forControlEvents: UIControlEvents.TouchUpInside)


        if (imageName != nil){

            button.setImage(UIImage(named: String("\(imageName!)_highlighted")), forState: UIControlState.Highlighted)

            button.setImage(UIImage(named: imageName!), forState: UIControlState.Normal)
        }

        if (title != nil){

            button.setTitle(title , forState: UIControlState.Normal)
            button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
            button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Highlighted)

            button.titleLabel?.font = UIFont.systemFontOfSize(15)

        }

        button.sizeToFit()

        customView = button


    }

}